#include "settings.h"
#include "Interfaces/newsettingsmenu.h"
#include <QSettings>
#include <QKeySequence>
#include <QDebug>

Settings::Settings(QObject* parent /*=0*/) : QObject(parent), newSettingsMenu(0) {
    settings.setPath(QSettings::IniFormat, QSettings::UserScope, "Settings.ini");
}

void Settings::changeHotkey(const QKeySequence &key) {
    setKey(key);
    qDebug() << "received!";
    emit newHotkeyHasBeenSet();
}

void Settings::openNewSettingsMenu() {
    if(!newSettingsMenu) // we don't want to make new settings window each time
        newSettingsMenu = new NewSettingsMenu;

    // hotkeys have to be changed immediately, so we should look for it
    connect(newSettingsMenu, SIGNAL(hotkeyLineEditHasBeenChanged(const QKeySequence&)), this, SLOT(changeHotkey(const QKeySequence&)));

    settingsMenu->setKey(getKey());
    settingsMenu->raise();
    settingsMenu->show();

}

QKeySequence Settings::getKey() {
    return settings.value("key", QVariant::fromValue(QKeySequence("F8"))).value<QKeySequence>();
}

void Settings::setKey(const QKeySequence &key) {
    settings.setValue("key", key);
}
